package weekMatch.one_345;

import java.beans.beancontext.BeanContext;
import java.util.*;

public class LeeCode_01 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(circularGameLosers(5, 2)));
    }
    private static int[] circularGameLosers(int n, int k) {
        Set<Integer> set = new HashSet<>();
        int start = 0, i = 1;
        set.add(0);
        while (true){
            int next = (start + k * i) % n;
            if (set.contains(next)){
                break;
            }else {
                start = next;
                set.add(next);
            }
            i++;
        }
        int[] ans = new int[n - set.size()];
        int index = 0;
        for (int j = 0; j < n; j++) {
            if (!set.contains(j)){
                ans[index++] = j + 1;
            }
        }
        return ans;
    }
}
